
	 /**  
	 * Project Name:BaseFramework  
	 * File Name:FileUploadTest.java  
	 * Package Name:com.sg.controller.demo  
	 * Date:2018年1月3日下午1:31:58 
	 *  
	*/  
	  
package com.sg.fileService.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.sg.common.ResultModel;
import com.sg.common.exception.BaseBusinessException;
import com.sg.fileService.entity.UploadResult;
import com.sg.fileService.service.IFileUploadService;
import com.sg.fileService.service.impl.AdvancedUploadStrategy;

/**  
	 * ClassName:FileUploadController <br/>  
	 * Function: ADD FUNCTION. <br/>  
	 * Reason:   ADD REASON. <br/>  
	 * Date:     2018年1月29日 下午11:00:00 <br/>  	 
	 * Update：      20180224 
	 * @author   Lwt
	 * @author   xzk   
	 * @version    
	 * @since    JDK 1.8  
	 * @see        
	 */
@CrossOrigin
@RequestMapping("/file")
@RestController
public class FileUploadController {

	@Autowired
	private IFileUploadService advancedUploadServiceImpl;
	
	@ResponseBody
	@RequestMapping(value="/upload",method={RequestMethod.POST, RequestMethod.GET})
	public ResultModel upload(HttpServletRequest request,HttpServletResponse response
			,@RequestParam(value="proPath",required=false)String proPath)throws BaseBusinessException{  
		UploadResult uploadResult = advancedUploadServiceImpl.uploadFile(request,proPath);
		ResultModel result = new ResultModel(Boolean.TRUE, "", "", uploadResult);
		//如果成功个数为0并且失败个数大于0则表示上传失败
		if(uploadResult.getSuccessFileCount()==0&&uploadResult.getFailFileCount()>0){
			result.setIsSuccess(false);
		}
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value="/upload/{proPath}",method={RequestMethod.POST})
	public ResultModel restUpload(HttpServletRequest request,HttpServletResponse response
			,@PathVariable("proPath")String proPath)throws BaseBusinessException{  
		UploadResult uploadResult = advancedUploadServiceImpl.uploadFile(request,proPath);
		ResultModel result = new ResultModel(Boolean.TRUE, "", "", uploadResult);
		//如果成功个数为0并且失败个数大于0则表示上传失败
		if(uploadResult.getSuccessFileCount()==0&&uploadResult.getFailFileCount()>0){
			result.setIsSuccess(false);
		}
		return result;
		
	}
	
	
	
}
  
	